/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2500.java
 * @Author : WangRuoyu
 * @Date 2022/12/17 9:08
 */

package leetcode;

import java.util.Arrays;

public class Q2500 {
    public int deleteGreatestValue(int[][] grid) {
        int res = 0;

        int m = grid.length;
        int n = grid[0].length;

        for (int i = 0; i < m; i++) {
            Arrays.sort(grid[i]);
        }

        for (int i = 0; i < n; i++) {
            int maxans = 0;
            for (int j = 0; j < m; j++) {
                if (maxans < grid[j][i]) {
                    maxans = grid[j][i];
                }
            }
            res += maxans;
        }
        return res;
    }

    public static void main(String[] args) {
        Q2500 sl = new Q2500();
        int[][] grid = {{4, 2, 1}, {3, 3, 1}};
        System.out.println(sl.deleteGreatestValue(grid));
    }
}